<?php

require_once 'config.inc.php';

class ZipContainer
{
  var $filename;

  function create($folderpath ,$foldername)
  {
    $zip = new ZipArchive();
    $filename = tempnam(TEMP_DIR,"zip_");

    if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE)
    {
      exit("cannot open <$filename>\n");
    }

    //TODO: subdirectory!
    $dir_listing = dir($folderpath);
    while(($dir_entry = $dir_listing->read()) !== false)
    {
      if (($dir_entry != ".") && ($dir_entry != ".."))
      {
        if (is_file($folderpath."/".$dir_entry))
        {
          $content_filename = $dir_entry;
          $zip->addFile($folderpath."/".$content_filename, $foldername."/".$content_filename);
        }
      } 
    }

    $zip->close();
    $this->filename = $filename;
  }
   
  function getSystemFilename()
  {
    return $this->filename;
  }

  function unlink()
  {
    unlink($this->filename);
  }

}

?>